
using System;


namespace ConsoleApplication
{
    public class CloneScript : Object {
        
        public static void Execute() {
            CloneScript originObj = new CloneScript(100);
            CloneScript shallowClone = originObj.GetCopy() as CloneScript;
            CloneScript deepClone = originObj.Clone() as CloneScript;

            originObj.value = 10;
            originObj.Inner.Value = 20;

            Console.WriteLine("origin:" + originObj.ToString());
            Console.WriteLine("shallowClone:" + shallowClone.ToString());
            Console.WriteLine("deepClone:" + deepClone.ToString());
        }

        public int value;
        public InnerCloneScript Inner;

        public CloneScript(int newValue) {
            value = newValue;
            Inner = new InnerCloneScript();
            Inner.Value = newValue * 2;
        }

        public  object GetCopy() {
            return MemberwiseClone();
        }

        public override string ToString() {
            return this.value + ":" + Inner.Value;
        }

        public object Clone() {
            CloneScript clone = new CloneScript(this.value);
            return clone;
        }
    }

    public class InnerCloneScript {
        public int Value;
    }
}
